package com.samsung.sds.test.editors;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;

import com.samsung.sds.test.Activator;

import java.net.MalformedURLException;
import java.net.URL;

public class JAVASCRIPTImages {
	static final URL BASE_URL = Activator.getDefault().getDefault().getDescriptor().getInstallURL();
	static final ImageDescriptor ICON_EDITOR;
	static final ImageDescriptor ICON_VIEW_VARIABLE;
	static final ImageDescriptor ICON_VIEW_FUNCTION;
	static final ImageDescriptor ICON_VIEW_DYNAMIC_CLASS;
	static final ImageDescriptor ICON_VIEW_CLASS;
	static final ImageDescriptor ICON_VIEW_CLASS_METHOD;
	static final ImageDescriptor ICON_VIEW_INSTANCE_METHOD;
	static final ImageDescriptor ICON_VIEW_CLASS_VARIABLE;
	static final ImageDescriptor ICON_VIEW_INSTANCE_VARIABLE;

	static {
		String iconPath = "icons/";

		ICON_EDITOR = createImageDescriptor(iconPath + "js.gif");
		ICON_VIEW_VARIABLE = createImageDescriptor(iconPath + "global_variable.gif");
		ICON_VIEW_FUNCTION = createImageDescriptor(iconPath + "func.gif");
		ICON_VIEW_CLASS = createImageDescriptor(iconPath + "class_obj.gif");
		ICON_VIEW_DYNAMIC_CLASS = createImageDescriptor(iconPath + "dyn_class_obj.gif");
		ICON_VIEW_CLASS_METHOD = createImageDescriptor(iconPath + "class_method.gif");
		ICON_VIEW_INSTANCE_METHOD = createImageDescriptor(iconPath + "instance_method.gif");
		ICON_VIEW_CLASS_VARIABLE = createImageDescriptor(iconPath + "class_variable.gif");
		ICON_VIEW_INSTANCE_VARIABLE = createImageDescriptor(iconPath + "instance_variable.gif");
	}

	private static ImageDescriptor createImageDescriptor(String path)
	{
		//			URL url = new URL(BASE_URL, path);
					URL url = FileLocator.find(Platform.getBundle(JavascriptExplorer.BUNDLE_NAME), new Path(path), null);
		
					return ImageDescriptor.createFromURL(url);

//		return ImageDescriptor.getMissingImageDescriptor();
	}
}
